import { defHttp } from '@/utils/http/axios';
import { EntityModel, CreateEntityParams, GetEntityListParams } from './model/entity';
import { BasicFetchResult } from '@/api/model/baseModel'
import { ErrorMessageMode } from '#/axios';

enum Api {
  BaseURL = '/datacenter/entities',
}

export function getEntityList(params: GetEntityListParams, mode: ErrorMessageMode = 'message') {
  return defHttp.get<BasicFetchResult<EntityModel>>(
    {
      url: Api.BaseURL,
      params,
    },
    {
      errorMessageMode: mode
    }
  );
}

export function getEntityListByConnection(params: GetEntityListParams, mode: ErrorMessageMode = 'message') {
  return defHttp.get<BasicFetchResult<EntityModel>>(
    {
      url: '/datacenter/entities/list-by-connection',
      params,
    },
    {
      errorMessageMode: mode
    }
  );
}

export function createEntity(params: CreateEntityParams, mode: ErrorMessageMode = 'message') {
  return defHttp.post<EntityModel>(
    {
      url: Api.BaseURL,
      params
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}

export function editEntity(id: number|string, params: EntityModel, mode: ErrorMessageMode = 'message') {
  return defHttp.put<EntityModel>(
    {
      url: `${Api.BaseURL}/${id}`,
      params
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}

export function deleteEntity(id: number|string, mode: ErrorMessageMode = 'message') {
  return defHttp.delete(
    {
      url: `${Api.BaseURL}/${id}`,
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}